var TreeUtil = {
  treeTransArray: function(tree, key) {
    return tree.reduce(function(con, item) {
      //console.log(con)
      //console.log(item)
      var callee = arguments.callee;
      con.push(item);
      if (item[key] && item[key].length > 0)
        item[key].reduce(callee, con);
      return con;
    }, []).map(function(item) {
      item[key] = [];
      return item;
    })
  },
  arrayTransTree: function(list, key, childKey) {
    if (list) {
      var tree = list.filter(function(parent) {
        var branchArr = list.filter(function(child) {
          return parent.id == child[key];
        });
        //parent[childKey] = [];
        if (branchArr.length > 0) {
          parent[childKey] = branchArr;
        }
        return !parent[key] || parent[key] == "";
      });
      return tree;
    }
  },
}
export default TreeUtil;
